#include <myhead.h>
#include "print.h"
#include "client.h"
#include "page.h"

//首页
void* page_to_index(){
	print_nav2("首页", (char*)client_loginname());
	//
	printf("[指令提示]:\n");
	printf("\t1-聊天功能\n");
	printf("\t2-群聊功能\n");
	printf("\t3-服务器远程控制功能\n");
	printf("\tQ-退出登录\n");

	char cmd=getInputChar(NULL);
	switch(cmd){
	case '1':
		return page_to_friend_index;
	case '2':
		return page_to_group_index;
	case '3':
		return page_to_myssh_index;
	case 'Q':
		return page_to_logout;
	}

	return page_to_index;
}


void* page_to_logout(pkg_t* retPkg, char* errmsg){
   //打包协议报
   char sendBuf[4096]={0};
   int len=pkg_pack_buf(sendBuf, MSG_TYPE_LOGOUT,1, client_loginname());
   //通信
   int ret=client_sendAndRet(sendBuf, len, retPkg, errmsg);
   if(ret != 0){
       print_red2("退出登录失败", errmsg);
       return page_to_welcome;
   }
   if(strcmp(pkg_get(retPkg, 0), "OK") != 0){
       print_red2("退出登录失败", pkg_get(retPkg, 1));
       return page_to_welcome;
   }

   print_green("退出登录成功\n");
   //停止发送心跳报文
   client_stop_heart();

   return page_to_welcome;
}


